#include <QtGui>
#include<QtGui>
#include <QtCore/QTextCodec>
#include <QTranslator>
#include "gv_home.h"
#include "gv_setuphomedialog.h"
#include "gv_systemhomedialog.h"
#include "gv_zoneshomedialog.h"
#include "gv_securityhomedialog.h"
#include "gv_monitormodedialog.h"
#include "gv_maintenancehome.h"
#include "gv_enterpassword.h"
#include "gv_setuphomedialog.h"
#include "gv_setting.h"

extern GV_Setting *gvsetting;
extern QDialog  *dialog;
gv_home::gv_home(QWidget *parent)
       : QDialog(parent)
{
    setupUi(this);

    QTranslator translator;
    translator.load(gvsetting->GV_GetLanguage(),".");
    qApp->installTranslator(&translator);
    reloadtext();

    //QIcon icon;
    //icon.addPixmap(QPixmap(QString::fromUtf8(":/images/icon_UserSetup.png")), QIcon::Normal, QIcon::Off);
    //jlh add for del label backgroud 100808
    QPalette pa;
    pa.setColor(QPalette::Background, QColor(0x00,0xff,0x00,0x00));
    TimeHintsLabel->setPalette(pa);
    //this->setAttribute(Qt::WA_TranslucentBackground);
    //TODO
    //end jlh add for del label backgroud 100808
    this->setStyleSheet("border-image: url(:/images/HomeBg.jpg);");
    UserSetupButton->setStyleSheet("border-image: url(:/images/icon_UserSetup.png);");
    SystemButton->setStyleSheet("border-image: url(:/images/icon_System.png);");
    ZonesButton->setStyleSheet("border-image: url(:/images/icon_Zones.png);");
    SecurityButton->setStyleSheet("border-image: url(:/images/icon_Security.png);");
    MonitorButton->setStyleSheet("border-image: url(:/images/icon_Monitor.png);");
    MaintenanceButton->setStyleSheet("border-image: url(:/images/icon_Maintenance.png);");

    //SetupHomeButton->setIcon((QIcon(":/images/icon_UserSetup.png")));
    TimeHintsLabel->setPalette(pa);
    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));

    /*
        if (m_labelTrans->parentWidget()->backgroundPixmap()){
        m_labelTrans->setBackgroundPixmap(*m_labelTrans->parentWidget()->backgroundPixmap());
        m_labelTrans->setBackgroundOrigin(QWidget::ParentOrigin);
        }
    */
    UserSetupLabel->setAttribute(Qt::WA_TranslucentBackground, true);
    UserSetupLabel->setAutoFillBackground(true);

    SystemLabel->setAttribute(Qt::WA_TranslucentBackground, true);
    SystemLabel->setAutoFillBackground(true);

    ZonesLabel->setAttribute(Qt::WA_TranslucentBackground, true);
    ZonesLabel->setAutoFillBackground(true);

    SecurityLabel->setAttribute(Qt::WA_TranslucentBackground, true);
    SecurityLabel->setAutoFillBackground(true);

    MonitorModeLabel->setAttribute(Qt::WA_TranslucentBackground, true);
    MonitorModeLabel->setAutoFillBackground(true);

    MaintenanceLabel->setAttribute(Qt::WA_TranslucentBackground, true);
    MaintenanceLabel->setAutoFillBackground(true);

    TimeHintsLabel->setAttribute(Qt::WA_TranslucentBackground, true);
    TimeHintsLabel->setAutoFillBackground(true);

    DateHintsLabel->setAttribute(Qt::WA_TranslucentBackground, true);
    DateHintsLabel->setAutoFillBackground(true);

    NameHintsLabel->setAttribute(Qt::WA_TranslucentBackground, true);
    NameHintsLabel->setAutoFillBackground(true);

    VersionLabel->setAttribute(Qt::WA_TranslucentBackground, true);
    VersionLabel->setAutoFillBackground(true);

    timer = new QTimer;
    connect(timer,SIGNAL(timeout()),this,SLOT(gv_chTime()));
    connect(UserSetupButton,SIGNAL(clicked()),this,SLOT(usersetup()));
    connect(SystemButton,SIGNAL(clicked()),this,SLOT(system()));
    connect(ZonesButton,SIGNAL(clicked()),this,SLOT(zones()));
    connect(SecurityButton,SIGNAL(clicked()),this,SLOT(security()));
    connect(MonitorButton,SIGNAL(clicked()),this,SLOT(monitormode()));
    connect(MaintenanceButton,SIGNAL(clicked()),this,SLOT(maintenance()));
    timer->start(1000);

    //retranslateUi(this);

}

void gv_home::reloadtext()
{

    NameHintsLabel->setText(tr("Basic Setting"));

    UserSetupLabel->setText(tr("User Setup"));
    SystemLabel->setText(tr("System"));
    ZonesLabel->setText(tr("Zones"));
    SecurityLabel->setText(tr("Security"));
    MonitorModeLabel->setText(tr("Monitor Mode"));
    MaintenanceLabel->setText(tr("Mantenance"));
}
void gv_home::gv_chTime()
{
    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
}

void gv_home::usersetup()
{
    //QMessageBox::about(this,tr("user's setup password"),gvsetting->GV_GetPassword(1));
    gvsetting->GV_SetShowDialog("User's Setup");
    gvsetting->GV_SetToDialog("Setup Home Dialog");
    gvsetting->GV_SetFromDialog("Home Dialog");

    //QDialog *dialog1 = new GV_SetupHomeDialog;
    QDialog *dialog1 = new GV_EnterPWDDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

void gv_home::system()
{
    QDialog *dialog1 = new GV_SystemHomeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

void gv_home::zones()
{
    QDialog *dialog1 = new GV_ZonesHomeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

void gv_home::security()
{
    QDialog *dialog1 = new GV_SecurityHomeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}
void gv_home::monitormode()
{
    QDialog *dialog1 = new GV_MonitormodeHomeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}
void gv_home::maintenance()
{
    QDialog *dialog1 = new GV_MaintenanceHomeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}
